Some objects such as lists are iterable and thus a for loop can be used to iterate over all items or a set of items based on a condition to peforms a fucntion or operation on each items in the list for example.)
In [2]:
my_iterable = [1,2,3]
for my_iterable in my_iterable:
print(my_iterable)
In [23]:
x=[1,2,3]
y= [str(a) + b + c for a in x for b in ['a','b','c'] for c in ['x','y','z']]
In [24]:
y
Out[24]:
In [26]:
from itertools import combinations, product
symbols = "abcdefghijklmnopqrstuvwxyz"
max_length = 2
class SiteSuffix:
# generator of all combinations
def words1(chars=symbols, max_len=max_length):
for length in xrange(1, max_length + 1):
for word in map(''.join, combinations(symbols, length)):
yield word
# generator of all combinations allowing repetitions
def words1(chars=symbols, max_len=max_length):
for length in xrange(1, max_length + 1):
for word in map(''.join, product(*[symbols]*length)):
yield word
chars = []
for word in words1():
#do something with word
chars.append(word)
c = chars[26::1]
print(str(c) + '\nFinished printing country code appendices, with love from rusha.')
c # should just quietly return this value ;)
In [66]:
from itertools import combinations, product
symbols = "abcdefghijklmnopqrstuvwxyz"
max_length = 2
class SiteSuffix:
# generator of all combinations
def words(chars=symbols, max_len=max_length):
for length in xrange(1, max_length + 1):
for word in map(''.join, combinations(symbols, length)):
yield word
# generator of all combinations allowing repetitions
def words(chars=symbols, max_len=max_length):
for length in xrange(1, max_length + 1):
for word in map(''.join, product(*[symbols]*length)):
yield word
chars = []
for word in words():
#do something with word
chars.append(word)
c = chars[26::1]
print(str(c) + '\nFinished printing country code appendices, with love from rusha.')
In [64]:
c
Out[64]:
In [56]:
In [55]:
In [ ]: